<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" />
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body class="pear-container">
        <style>
            .layui-input-block input {
                width: 300px;
            }
        </style>

        <div class="layui-card">
            <div class="layui-card-body">

                <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">小程序配置</li>
                    <li>微信支付配置</li>
                </ul>
                <div class="layui-tab-content">

                    <!-- 基本信息 -->
                    <div class="layui-tab-item layui-show">

                        <form class="layui-form" lay-filter="miniInfo">
                            <div class="layui-form-item">
                                <label class="layui-form-label">原始ID</label>
                                <div class="layui-input-block">
                                    <input type="text" name="original_id" placeholder="请输入原始ID" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">APP ID</label>
                                <div class="layui-input-block">
                                    <input type="text" name="app_id"  placeholder="请输入APP ID" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">App Secret</label>
                                <div class="layui-input-block">
                                    <input type="text" name="app_secret"  placeholder="请输入APP Secret" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="saveMiniInfo">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>

                    <div class="layui-tab-item">

                        <form class="layui-form" lay-filter="wechatPayInfo">
                            <div class="layui-form-item">
                                <label class="layui-form-label">商户号</label>
                                <div class="layui-input-block">
                                    <input type="text" name="mch_id" placeholder="请输入商户号" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">证书序列号</label>
                                <div class="layui-input-block">
                                    <input type="text" name="cert_no"  placeholder="请输入证书序列号" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">Apiv2密钥</label>
                                <div class="layui-input-block">
                                    <input type="text" name="apiv2_key"  placeholder="请输入Apiv2密钥" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">Apiv3密钥</label>
                                <div class="layui-input-block">
                                    <input type="text" name="apiv3_key"  placeholder="请输入Apiv3密钥" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">证书(apiclient_cert.pem)</label>
                                <div class="layui-input-block">
                                    <span></span>
                                    <input type="text" style="display:none" name="cert" value="" />
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="cert" permission="app.admin.upload.file">
                                        <i class="layui-icon layui-icon-upload"></i>上传文件
                                    </button>
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="attachment-choose-cert" permission="app.admin.upload.attachment">
                                        <i class="layui-icon layui-icon-align-left"></i>选择文件
                                    </button>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">私钥(apiclient_key.pem)</label>
                                <div class="layui-input-block">
                                    <span></span>
                                    <input type="text" style="display:none" name="pem" value="" />
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="pem" permission="app.admin.upload.file">
                                        <i class="layui-icon layui-icon-upload"></i>上传文件
                                    </button>
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="attachment-choose-pem" permission="app.admin.upload.attachment">
                                        <i class="layui-icon layui-icon-align-left"></i>选择文件
                                    </button>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="saveWechatPayInfo">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>

                </div>
            </div>

            </div>
        </div>


        <script src="/app/admin/component/layui/layui.js"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script>

            layui.use(["form","upload","util"], function() {
                var form = layui.form;
                // 上传文件
                layui.use(['upload'], function () {
                    let input = layui.$("#cert").prev();
                    input.prev().html(layui.util.escape(input.val()));
                    layui.$("#attachment-choose-a93qk").on("click", function () {
                        parent.layer.open({
                            type: 2,
                            title: "选择附件",
                            content: "/app/admin/upload/attachment",
                            area: ["95%", "90%"],
                            success: function (layero, index) {
                                parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                    input.val(data.url).prev().html(layui.util.escape(data.url));
                                });
                            }
                        });
                    });
                });
                layui.upload.render({
                    elem: "#cert",
                    url: "/app/admin/upload/file",
                    accept: "file",
                    field: "__file__",
                    done: function (res) {
                        this.item.prev().val(res.data.url).prev().html(layui.util.escape(res.data.url));
                    }
                });
                // 上传文件
                layui.use(['upload'], function () {
                    let input = layui.$("#pem").prev();
                    input.prev().html(layui.util.escape(input.val()));
                    layui.$("#attachment-choose-asj2r").on("click", function () {
                        parent.layer.open({
                            type: 2,
                            title: "选择附件",
                            content: "/app/admin/upload/attachment",
                            area: ["95%", "90%"],
                            success: function (layero, index) {
                                parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                    input.val(data.url).prev().html(layui.util.escape(data.url));
                                });
                            }
                        });
                    });
                });
                layui.upload.render({
                    elem: "#pem",
                    url: "/app/admin/upload/file",
                    accept: "file",
                    field: "__file__",
                    done: function (res) {
                        this.item.prev().val(res.data.url).prev().html(layui.util.escape(res.data.url));
                    }
                });
            });

            // 基础设置
            layui.use(["upload", "layer", "popup"], function() {
                let $ = layui.$;
                let form = layui.form;

                // image
                let input = $("#image").prev();
                input.prev().attr("src", input.val());
                layui.$("#attachment-choose-image").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#image",
                    url: "/app/admin/upload/avatar",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    done: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });

                // 提交
                form.on("submit(saveMiniInfo)", function(data){
                    $.ajax({
                        url: "/app/admin/config/update",
                        dataType: "json",
                        type: "POST",
                        data: {mini: data.field},
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功");
                        }
                    });
                    return false;
                });

                // 提交
                form.on("submit(saveWechatPayInfo)", function(data){
                    $.ajax({
                        url: "/app/admin/config/update",
                        dataType: "json",
                        type: "POST",
                        data: {wechatPay: data.field},
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功");
                        }
                    });
                    return false;
                });
            });



            layui.use(["form"], function () {
                let form = layui.form;
                let $ = layui.$;
                $.ajax({
                    url: "/app/admin/config/get",
                    dataType: "json",
                    success: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        form.val('miniInfo', res.mini);
                        form.val('wechatPayInfo', res.wechatPay);
                    }
                });

            });

        </script>

    </body>
</html>
